<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./libs/vue2.js"></script>
</head>
<body>
    <div id="app">
        <button @click="addItem">通过数组索引向数组中添加元素</button>
        <ul>
            <li v-for="item in list">{{item}}</li>
        </ul>
        <hr>
        <button @click="addAttr">向对象中动态增加属性</button>
        <ul>
            <li v-for="item in user">{{item}}</li>
        </ul>
    </div>
</body>
<script>
    new Vue({
        el:'#app',
        data:{
            list:['苹果','香蕉','水蜜桃'],
            user:{
                name:'jack'
            }
        },
        methods:{
            addItem(){
                let index=this.list.length;
                // this.list[index]='西瓜';
                // this.$set(this.list,index,'西瓜');
                Vue.set(this.list,index,'西瓜');
                console.log(this.list);
            },
            addAttr(){
                // this.user.age=20;
                // this.user.address='中国';
                this.$set(this.user,'age',20);
                Vue.set(this.user,'address','中国');
                console.log(this.user);
            }
        }
    });
</script>
</html>